package com.example.charge.vm

import com.example.charge.api.ChargeApiService
import com.example.charge.entity.ChargeEntity
import com.example.charge.model.ChargeRepository
import com.example.charge.model.ChargeResultData
import com.example.common.view.vm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ChargeViewModel @Inject constructor(private val apiService: ChargeApiService) : BaseViewModel<ChargeRepository,ChargeResultData<List<ChargeEntity>>>(){
    fun getChargeList(payerId:Int){
        mViewModelScope.launch (mDispatcher){
            try {
                val result = apiService.getChargeList(payerId)
                mSuccessLiveData.postValue(result)
            } catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}